package bobaini.com.mid_easy;

import bobaini.com.util.RabbitMqUtils;
import com.rabbitmq.client.Channel;

import java.util.Scanner;

/**
 * ClassName: Productor
 * author: bob.ly
 * Version: 1.0.0
 * DateTime: 2021/07/07-22:28:00
 * Description:
 */
public class Productor {
    /**
     * 声明一个队列名称
     */
    private static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        /**
         * 声明消息队列
         * param1:指定队列的名称
         * param2:是否持久化
         * param3:是否只让一个消费者消费
         * param4:是否自动删除
         * param5:其他参数
         */
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);
        /**
         * 手动从控制台当中接受信息
         */
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String message = scanner.next();
            channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
            System.out.println("发送消息完成:" + message);

        }
    }
}
